load(":DIY_rule/rule_lib/my_compile.bzl", "make_exe", "make_lib")
load("@rules_cc//cc:defs.bzl", "cc_binary")

make_lib(
    name = "math",
    header_list = [
        ":not_one_package/to_include/toolkit.h",
    ],
    include_path_list = [
        ":not_one_package",
    ],
    output_name = "libmath.a",
    src_list = [
        ":not_one_package/src/math_tool.cpp",
        ":not_one_package/src/part2.cpp",
    ],
)

# 会失败, 编译命令已检查; 可能sandbox与本机隔离
# 解决方法: 增加编译参数 -B /usr/bin
make_exe(
    name = "failed_main",
    exe_name = "failed_main.exe",
    header_list = [
        ":not_one_package/to_include/toolkit.h",
    ],
    include_dir_list = [
        "//mini_proj:not_one_package",
    ],
    lib_file_list = [
        ":math",
    ],
    src_list = [
        "//mini_proj:not_one_package/src/main.cpp",
    ],
)

cc_library(
    name = "formal_math",
    srcs = [
        ":not_one_package/src/math_tool.cpp",
        ":not_one_package/src/part2.cpp",
    ],
    hdrs = [":not_one_package/to_include/toolkit.h"],
    # NOTE: 不支持:符号 :not_one_package
    # NOTE: 错误路径:
    # includes = ["mini_proj/not_one_package"],
    includes = ["./not_one_package"],
)

cc_binary(
    name = "main.exe",
    srcs = [
        ":not_one_package/src/main.cpp",
    ],
    deps = [":formal_math"],
)

cc_binary(
    name = "unit_test.exe",
    srcs = [":not_one_package/src/unit_test.cpp"],
    deps = [
        ":formal_math",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_binary(
    name = "unit_test2.exe",
    srcs = ["//mini_proj:not_one_package/src/unit_test.cpp"],
    deps = [
        "//mini_proj:formal_math",
        "@com_google_googletest//:gtest_main",
    ],
)
